home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Devices / Disk Icons / compgetinfo.c next >
Encoding:
C/C++ Source or Header  |  1994-11-03  |  3.5 KB  |  143 lines  |  [TEXT/MPS ]

  1. #include <Memory.h>
  2. #include <Types.h>
  3. #include <Menus.h>
  4. #include <Windows.h>
  5. #include <Dialogs.h>
  6. #include <Fonts.h>
  7. #include <Devices.h>
  8. #include <Printing.h>
  9. #include <Controls.h>
  10. #include <Errors.h>
  11. #include <Quickdraw.h>
  12.  
  13. /*    this is the data structure pointed to in the result of the
  14.     disk driver call csCode=21 (get ICN#/comment).  This call
  15.     works on all devices.
  16. */
  17.  
  18. typedef struct TInfoBlk {
  19.     unsigned char    icon[128];        /* icon */
  20.     unsigned char    mask[128];        /* mask */
  21.     Str255            infoString;        /* info string (for get info) */
  22. } TInfoBlk,*TInfoPtr;
  23.  
  24. void GetDiskInfo(short driverRefNum,short driveNum,TInfoPtr *dataBlk);
  25. void DrawInfo(TInfoPtr infoBlock);
  26. void GetAllInfo(void);
  27. void GetAllInfoYourWay(void);
  28.  
  29. #ifdef powerc
  30.    QDGlobals    qd;
  31. #endif
  32.  
  33. void main(void)
  34. {
  35.     WindowPtr theWindow;
  36.     Rect wBounds;
  37.  
  38.     InitGraf(&qd.thePort);
  39.     InitFonts();
  40.     InitWindows();
  41.     InitMenus();
  42.     TEInit();
  43.     InitDialogs(nil);
  44.     FlushEvents(everyEvent,0);
  45.     InitCursor();
  46.     
  47.     SetRect(&wBounds,40,40,100,100);
  48.     theWindow = NewWindow (nil,&wBounds,(StringPtr)"\pIcons",true,documentProc,
  49.                 (WindowPtr)(-1),true,0L);
  50.     SetPort(theWindow);
  51.     GetAllInfo();
  52.     DisposeWindow(theWindow);
  53. }
  54.  
  55.  
  56. /*    This routine traverses the currently mounted volumes
  57.     index using PBHGetVInfo().  The drive # and device
  58.     driver number for each volume is extracted from the
  59.     parameter block, and passed into GetDiskInfo() to
  60.     call the disk drivers.
  61.     
  62.     Once the data has been retrieved, the icon is plotted
  63. */
  64.  
  65. void GetAllInfo(void)
  66. {
  67.     HParamBlockRec vBlock;    /* volume parameter block used to traverse mounted vols */
  68.     OSErr err;
  69.     TInfoPtr dataBlk;        /* pointer used to point to result of csCode=21 call */
  70.     
  71.     vBlock.volumeParam.ioNamePtr = nil;
  72.     vBlock.volumeParam.ioVRefNum = 0;
  73.     vBlock.volumeParam.ioVolIndex = 1;
  74.     
  75.     do {
  76.         err = PBHGetVInfo (&vBlock,false);
  77.         vBlock.volumeParam.ioVolIndex++;
  78.         if (err==noErr) {
  79.             GetDiskInfo(vBlock.volumeParam.ioVDRefNum,
  80.                         vBlock.volumeParam.ioVDrvInfo,&dataBlk);
  81.             if (dataBlk)
  82.                 DrawInfo(dataBlk);
  83.         }
  84.     } while (err==noErr);
  85. }
  86.  
  87.  
  88. /*    GetDiskInfo() makes the call to the volume's driver to get the
  89.     volume icon and info string.  A pointer to this data is returned
  90.     by reference in dataBlk
  91.     
  92.     This routine tries to call the disk's driver with csCode=22,
  93.     which attempts to get info on a specific physical volume.
  94.     
  95.     If the csCode=22 call fails, I call csCode=21 to get the generalized
  96.     media icon.
  97.     
  98.     Both calls are documented in IM V-470
  99. */
  100.  
  101. void GetDiskInfo(short driverRefNum,short driveNum,TInfoPtr *dataBlk)
  102. {
  103.     ParamBlockRec pBlock;
  104.     OSErr err;
  105.     
  106.     pBlock.cntrlParam.ioVRefNum = driveNum;
  107.     pBlock.cntrlParam.ioCRefNum = driverRefNum;
  108.     pBlock.cntrlParam.csCode = 22;
  109.     
  110.     err = PBControl(&pBlock,false);
  111.     if (err==controlErr) {
  112.         pBlock.cntrlParam.ioVRefNum = driveNum;
  113.         pBlock.cntrlParam.ioCRefNum = driverRefNum;
  114.         pBlock.cntrlParam.csCode = 21;
  115.         err = PBControl(&pBlock,false);
  116.     }
  117.     
  118.     if (err==noErr)
  119.         *dataBlk = (TInfoPtr) *(Ptr *)pBlock.cntrlParam.csParam; /* messy way to get the locn out */
  120.     else *dataBlk = nil;
  121. }
  122.  
  123.  
  124.  
  125. /*    this routine uses CopyBits to draw the icon on the screen (ignoring the mask and
  126.     the info string).  Make sure you put up a window and call SetPort() first!
  127. */
  128.  
  129. void DrawInfo(TInfoPtr infoBlock)
  130. {
  131.     BitMap iconMap;
  132.     Rect destRect;
  133.     
  134.     iconMap.baseAddr = (Ptr)infoBlock;
  135.     iconMap.rowBytes = 4;
  136.     SetRect(&iconMap.bounds,0,0,32,32);
  137.     SetRect(&destRect,0,0,32,32);
  138.     OffsetRect(&destRect,10,10);
  139.     CopyBits(&iconMap,&qd.thePort->portBits,&iconMap.bounds,&destRect,
  140.             srcCopy,nil);
  141.     while (!Button());
  142.     while (Button());
  143. }